/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.DataWrapper;
import model.Product;

/**
 *
 * @author moustafa
 */
public class EditProduct extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{
        DataWrapper wrapper = DataWrapper.getInstance();
        int productID = Integer.parseInt((String)request.getSession(false).getAttribute("product_id"));
        String productName = request.getParameter("product_name");
        String productDescrition = request.getParameter("product_description");
        String productImageURL = request.getParameter("product_image_url");
        String productStatus = request.getParameter("product_status");
        float productLPrice = Float.parseFloat(request.getParameter("product_list_price"));
        float productMPrice = Float.parseFloat(request.getParameter("product_min_price"));
        String productCatalogURL = request.getParameter("warehouse_catalog_url");
        wrapper.updateProduct(new Product(productID, productName, productDescrition, productImageURL, productStatus, productLPrice, productMPrice, productCatalogURL), wrapper.getConnection());
        request.getSession().setAttribute("added_message", "Product Successfully updated!");
        try {
            getServletContext().getRequestDispatcher("/admin_pages/edit_product.jsp").forward(request, response);
        } catch (IOException ex) {
            Logger.getLogger(AddWarehouse.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{

    }

}
